<?php
class SectionBox extends CWidget {
	public $subCategoryCount;
    public $categoryId;
    public $subCategories;
    public $category;
	
	public function init() {
        $this->category = TermsTaxonomy::model()->findByPk($this->categoryId);
        $criteria = new CDbCriteria;
        $criteria->condition = 'parent = '.$this->categoryId;
        $criteria->limit = $this->subCategoryCount;
        $this->subCategories = TermsTaxonomy::model()->with(array(
                'terms', 
            )
        )->findAll($criteria);
        foreach($this->subCategories as &$category) {
            $category->posts = Posts::model()->published()->section()->findByCategoryId($category->termTaxonomyId);
        }

	}
	
	public function run() {
		$this->renderContent();
	}

	public function renderContent($return = false) {
		return $this->render('section-box', 
            array(
                'category' => $this->category, 
                'subCategories' => $this->subCategories, 
                'sectionSize' => 10
            ), $return);
	}
}
